import { saveAs } from 'file-saver'
export default function (map) {
  const save = (map) => {
    map.value.once('postcompose', function (event) {
      var canvas = event.context.canvas
      if (navigator.msSaveBlob) {
        navigator.msSaveBlob(canvas.msToBlob(), 'map.png')
      } else {
        canvas.toBlob(function (blob) {
          saveAs(blob, 'map.png')
        })
      }
    })
    map.value.renderSync()
  }
  return { save }
}
